<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<base href="<%=basePath%>">
<!DOCTYPE html>
<html lang="zh" class="no-js">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8"/>
    <title>预览笔记</title>
    <link rel="stylesheet" href="/markdowns/trueEditPage/css/style.css"/>
    <link rel="stylesheet" href="/markdowns/css/editormd.css"/>
    <link rel="stylesheet" href="/markdowns/menu/css/reset.css"> <!-- CSS reset -->
    <link rel="stylesheet" href="/markdowns/menu/css/style.css"> <!-- Resource style -->
    <script src="/markdowns/menu/js/modernizr.js"></script> <!-- Modernizr -->
</head>
<body>
<header class="cd-main-header">
    <a class="cd-logo" href="#"><img src="/markdowns/menu/img/cd-logo.svg" alt="Logo"></a>

    <ul class="cd-header-buttons">
        <li><a class="cd-search-trigger" href="#cd-search">Search<span></span></a></li>
        <li><a class="cd-nav-trigger" href="#cd-primary-nav">Menu<span></span></a></li>
        <style>
            a {
                cursor: pointer;
            }
        </style>
    </ul> <!-- cd-header-buttons -->
</header>
<main class="cd-main-content">
    <!-- your content here -->
    <script src="/markdowns/trueEditPage/js/jquery.min.js"></script>
    <script>
        $.ajax({
            url: "/proving/pvLogin.do",
            type: "post",
            async: true,
            success: function (result) {
                console.log(result)
                var title = result + "aaaa";
                if (title.indexOf("<title>用户登录</title>") >= 0) {
                    alert("登陆信息过期,请重新登陆")
                    window.location.href = "/views/login/index.jsp";
                }
            }
        });
    </script>
    <div id="layout">
        <div id="test-editormd">
        <textarea id="note" style="display:none;"># 在这里写文章标题哦!

在这里写正文</textarea>
        </div>
    </div>
    <script src="/markdowns/trueEditPage/js/jquery.min.js"></script>
    <script src="/markdowns/editormd.js"></script>
    <script src="/markdowns/jquery.cookie.js"></script>
    <script>
        $(document).keydown(function (e) {
            var len = 0;
            if (e.ctrlKey == true && e.keyCode == 83) {
                console.log('ctrl+s');
                var cookieVal = document.cookie;
                console.log(cookieVal);
                var cookieid = cookieVal.match(/KEYBOARD_IDENTITY=(\S*);/)[1];
                var note = $("#note").val();
                var title = note.substring(note.indexOf('#'), note.indexOf('\n')).replace("#", "");
                console.log("cookie:-------->"+cookieid)
                console.log(note)
                console.log("title--->" + title)
                if (title == null || title == "") {
                    len = 1;
                    alert("获取标题失败!标题请写在第一行!且下一行必须有内容")
                }
                if(len == 0){
                    obj = {
                        note: note,
                        title: title,
                        identity: cookieid
                    }
                    $.ajax({
                        url: "/notesApi/notes.do",
                        type: "post",
                        data: obj,
                        success: function (result) {
                            if (result.code == 100) {
                                alert(result.msg)
                            } else if (result.code == 200) {
                                alert(result.success)
                            }
                        }
                    })
                }
                return false;
            }
        });
    </script>
    <script type="text/javascript">
        var testEditor;

        $(function () {
            // You can custom @link base url.
            editormd.urls.atLinkBase = "https://github.com/";

            testEditor = editormd("test-editormd", {
                width: "100%",
                height: 800,
                toc: true,
                todoList: true,
                watch : true,
                path: '/markdowns/lib/'
            });
        });
    </script>
    <div class="cd-overlay"></div>
</main>

<nav class="cd-nav">

</nav>
<script src="/markdowns/menu/js/jquery-2.1.0.min.js"></script>
<script src="/navigation/append_navigation.js"></script>
<script src="/markdowns/menu/js/jquery.mobile.custom.min.js"></script>
<script src="/markdowns/menu/js/main.js"></script>
</body>
</html>